home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Selection / Multimedia Selection Volume One - CD-ROM / MULTIMEDIA SELECTION____________.ISO / programz / ldb / cbinder.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-25  |  3.9 KB  |  144 lines

  1. /*
  2.  
  3.     cbinder.hpp
  4.     10-25-91
  5.     Copy Binder: Loose Data Binder v 1.5
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072 USA
  14.  
  15.     John Small
  16.     Voice: (703) 759-3838
  17.     CIS: 73757,2233
  18.  
  19. */
  20.  
  21. #ifndef CBINDER_HPP
  22. #define CBINDER_HPP
  23.  
  24. #ifndef SBINDER_HPP
  25. #include "sbinder.hpp"
  26. #endif
  27.  
  28. #include <string.h>
  29.  
  30. #define ID_CBinder    3
  31.  
  32. #define CBDR_STRING    0
  33.  
  34. /*
  35.     CBinder is a SBinder that doesn't require its nodes
  36.     to be derived from Streamable.  As a result the 
  37.     nodes MUST not be multiply linked since they don't 
  38.     have Streamable's built in double ownership 
  39.     protection or multiple reference streaming 
  40.     capabilities.  In other words the nodes must be 
  41.     solely owned by the CBinder and appear only once 
  42.     bound within.  The CBinder also provides for cloning
  43.     and copying of your data on the fly.  Since every 
  44.     LDB requires that its nodes must all be either 
  45.     statically or dynamically allocated, allowing the 
  46.     CBinder to clone some nodes forces the requirement 
  47.     that all nodes be dynamically allocated.  Thus the 
  48.     CBinder constructor always sets the BDR_OK_FREE flag.
  49.         
  50.     So we see that the CBinder nodes MUST be dynamically
  51.     allocated fixed size data or C strings which the 
  52.     CBinder defaults to.  A CBinder should only be used 
  53.     to bind native data types and structures or classes 
  54.     without virtual functions or suballocated memory (or
  55.     other pointers) or otherwise requiring destructor 
  56.     calls.  See manual for details of binding these kinds
  57.     of structures and classes in decendents of CBinder.
  58. */
  59.     
  60.     
  61. class CBinder : public SBinder  {
  62.     unsigned sizeofData;
  63. protected:
  64.     void construct(unsigned sizeofData)
  65.         { this->sizeofData = sizeofData; }
  66.     // void destruct()  {}
  67.     virtual int  Dfree(voiD D)
  68.         { return (D? delete D, 1 : 0); }
  69.     virtual int  Dattach(voiD)
  70.         { return 1; }
  71.     virtual void Ddetach(voiD)
  72.         { return; }
  73.         /*
  74.             If your derived class overrides
  75.             Dattach() and Ddetach() it is 
  76.             likely that restream() needs
  77.             overriding also!
  78.         */
  79.     virtual ostream& store(ostream& os);
  80.     static  StreamablE load(istream& is,
  81.         StreamablE InstancE);
  82.     virtual void Dstore(ostream& os, voiD D);
  83.     virtual voiD Dload(istream& is);
  84.     virtual voiD Dclone(const voiD D);
  85.         /*
  86.             Think of Dclone() as a copy
  87.             initilizer for your data.
  88.         */
  89.     virtual voiD Dcopy(voiD D, const voiD S);
  90.         /*
  91.             Think of Dcopy() like an assignment
  92.             operator.  If (!D || !S || D == S)
  93.             return voiD0 otherwise perform what
  94.             operator=() would do on your data.
  95.         */
  96. public:
  97.     enum { ID_CLASS = ID_CBinder };
  98.     CBinder(StreamableClassRegistry& dummy,
  99.         unsigned id = ID_CLASS) :
  100.         SBinder(dummy,id) {}
  101.     CBinder(unsigned sizeofData = CBDR_STRING,
  102.         unsigned maxNodes = BDR_MAXNODES,
  103.         unsigned limit = BDR_LIMIT,
  104.         unsigned delta = BDR_DELTA);
  105.     static void registerClass(unsigned id = ID_CLASS,
  106.         StreamablE (*loader)(istream& is,
  107.         StreamablE InstancE) = load)
  108.         { Streamable :: registerClass(id,loader); }
  109.     virtual unsigned restream()
  110.         { return Streamable::restream(); }
  111.     virtual ~CBinder()  { allFree(); }
  112.     unsigned SizeofData()  { return sizeofData; }
  113.     voiD atInsCLN(unsigned n, const voiD D);
  114.     voiD atFreeCPY(unsigned n, voiD D);
  115.     voiD atPutCLN(unsigned n, const voiD D);
  116.     voiD atPutCPY(unsigned n, const voiD D)
  117.         { return Dcopy(atGet(n),D); }
  118.     voiD atGetCPY(unsigned n, voiD D)
  119.         { return Dcopy(D,atGet(n)); }
  120.     voiD topCPY(voiD D)  { return Dcopy(D,atGet(0)); }
  121.     voiD currentCPY(voiD D)
  122.         { return Dcopy(D,atGet(CurNode())); }
  123.     operator char *();
  124.     voiD bottomCPY(voiD D)
  125.         { return Dcopy(D,atGet(Nodes()-1)); }
  126.     voiD pushCLN(const voiD D);
  127.     voiD popFreeCPY(voiD D);
  128.     voiD insQCLN(const voiD D);
  129.     voiD rmQFreeCPY(voiD D);
  130.     voiD unQFreeCPY(voiD D);
  131.     voiD insCLN(const voiD D);
  132.     voiD insSortCLN(const voiD D);
  133.     voiD delFreeCPY(voiD D);
  134.     voiD nextCPY(voiD D);
  135.     voiD prevCPY(voiD D);
  136.  
  137. };
  138.  
  139. typedef CBinder * CBindeR;
  140.  
  141.  
  142. #endif
  143.  
  144.